package com.derbysoft.dswitch.adapter.ihg.web.action.admin.setting.freemeal;

import com.derbysoft.dswitch.adapter.ihg.common.domain.FreeMealStrategy;
import com.derbysoft.dswitch.adapter.ihg.common.repository.FreeMealStrategyRepository;
import com.derbysoft.dswitch.adapter.ihg.web.action.support.BaseAction;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * User: jason
 * Date: 2013-01-06
 */
public class DelAction extends BaseAction {

    @Autowired
    private FreeMealStrategyRepository freeMealStrategyRepository;

    private FreeMealStrategy freeMealStrategy;

    @Action("delete")
    public String execute() {
        if (freeMealStrategy.getId() == null) {
            return EDIT;
        }
        FreeMealStrategy existed = freeMealStrategyRepository.load(freeMealStrategy.getId());
        if (existed != null) {
            freeMealStrategyRepository.delete(existed);
        }
        return LIST;
    }

    public FreeMealStrategy getFreeMealStrategy() {
        return freeMealStrategy;
    }

    public void setFreeMealStrategy(FreeMealStrategy freeMealStrategy) {
        this.freeMealStrategy = freeMealStrategy;
    }
}
